package com.ctshk.rpc.custom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.custom.base.CustomBaseMapper;
import com.ctshk.rpc.custom.dto.quotation.TouristPriceDTO;
import com.ctshk.rpc.custom.dto.trip.QuotationTouristTypeDTO;
import com.ctshk.rpc.custom.entity.CustomizedTripScheduleTouristPrice;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 团期游客服务价格 Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-21
 */
public interface CustomizedTripScheduleTouristPriceMapper extends CustomBaseMapper<CustomizedTripScheduleTouristPrice> {

    /**
     * 获取人均服务项列表
     * @param serviceItemId
     * @return
     */
    @Select("SELECT a.tourist_type_name,a.total_price,b.people_num,b.age_begin,b.age_end\n" +
            "FROM t_customized_trip_schedule_tourist_price a LEFT JOIN t_customized_quotation_tourist_type b ON a.tourist_type_id = b.id\n" +
            "where a.service_item_id = #{service_item_id} and a.is_deleted = 0")
    List<TouristPriceDTO> queryByServiceItem(@Param("service_item_id") Long serviceItemId);

    /**
     * 获取服务项目旅客类型列表
     * @param packageId
     * @return
     */
    @Select("SELECT a.id,a.tourist_type_name AS label,a.tourist_type_id,SUM(a.total_price) AS price,b.main_data_id AS value,(c.total_people - c.order_people) AS peopleNum,b.age_begin,b.age_end\n" +
            "FROM t_customized_trip_schedule_tourist_price a LEFT JOIN t_customized_quotation_tourist_type b ON a.tourist_type_id = b.id\n" +
            "LEFT JOIN t_customized_trip_schedule_tourist_count c ON b.main_data_id = c.tourist_type_id\n" +
            "WHERE a.package_id = #{package_id} AND c.schedule_id = #{schedule_id}\n" +
            "GROUP BY b.main_data_id ORDER BY a.sort ASC")
    List<QuotationTouristTypeDTO> queryListByPackage(@Param("package_id")Long packageId,@Param("schedule_id")Long scheduleId);
}
